/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.BugRS.buz;

import com.aptech.BugRS.dao.DepartmentDAO;
import com.aptech.BugRS.enity.DepartmentDTO;
import java.util.ArrayList;

/**
 *
 * @author KISS
 */
public class DepartmentBUZ {

    DepartmentDAO dao = null;
    private String lastError = "";

    public DepartmentBUZ() {
        dao = new DepartmentDAO();
    }

    /**
     *
     * @param department
     * @return boolean
     */
    public boolean create(DepartmentDTO dep) {
        if (!dep.Validate()) {
            //this.lastError = history.getValidateDescription();
            setLastError("E_Complaint error");
            return false;
        }
        if (dao.isExits(dep)) {
            this.lastError = dao.getLastError();
            return false;
        }
        if (!dao.Create(dep)) {
            this.lastError = dao.getLastError();
            return false;
        }
        this.setLastError(dao.getLastError());
        return true;
    }

    /**
     * Read all Department
     * @return list of Department
     */
    public ArrayList<DepartmentDTO> findByAll() {
        return dao.ReadByAll();
    }

    /**
     * Read by ID of department
     * @param id
     * @return department
     */
    public DepartmentDTO findByID(int id) {
        return dao.ReadByID(id);
    }

    /**
     *  Update department
     * @param department
     * @return boolean
     */
    public boolean store(DepartmentDTO dep) {
        if (!dep.Validate()) {
            setLastError("Entity Complaint Error");
            return false;
        }
        if (!dao.Update(dep)) {
            this.lastError = dao.getLastError();
            return false;
        }
        setLastError(dao.getLastError());
        return true;
    }

    /**
     * @return the lastError
     */
    public String getLastError() {
        return lastError;
    }

    /**
     * @param lastError the lastError to set
     */
    public void setLastError(String lastError) {
        this.lastError = lastError;
    }
}
